<template>
  <div class="modal" v-show="$store.state.LoginShow">
    <div class="modal_in" @click="closeLogin"></div>
    <div class="content">
      <div class="content_top">
        <span class="topl">登录</span>
        <span class="topr" @click="closeLogin">X</span>
      </div>
      <div class="other" v-show="isshow == 1">
        <img src="../assets/登录.png" alt="" />
        <button @click="isshow = 2">选择其他方式登录</button>
      </div>
      <div class="phone tanxin" v-show="isshow == 2">
        <div class="phonel">
          <div class="img"><img src="../assets/电脑.png" alt="" /></div>
          <div class="phoneLogin button" @click="goLogin">手机号登录</div>
          <div class="zhuce button" @click="gozhuce">注册</div>
          <div class="agree tanxin">
            <div
              :class="kuangshow == true ? 'kuang blue' : 'kuang'"
              @click="kuangshow = !kuangshow"
            >
              √
            </div>
            <span>同意《服务条款》《隐私政策》《儿童隐私政策》</span>
          </div>
        </div>
        <div class="phoner">
          <p><i class="iconfont icon-weixin"></i>微信登录</p>
          <p><i class="iconfont icon-qq-copy-copy"></i>qq登录</p>
          <p><i class="iconfont icon-weibo"></i>微博登录</p>
          <p>
            <i class="iconfont icon-airudiantubiaohuizhi-zhuanqu_yiwutong"></i
            >网易邮箱账号登录
          </p>
        </div>
      </div>
      <div class="zhuce" v-show="isshow == 3">
        <input
          type="text"
          placeholder="请输入手机号"
         
          class="input1"
        />
        <input
          type="text"
          placeholder="请设置密码"
          
          class="input2"
        />
        <div class="next">下一步</div>
        <div class="return">
          <span @click="isshow == 2">返回登录</span>
        </div>
      </div>
      <div class="login" v-show="isshow == 4">
        <input
          type="text"
          placeholder="请输入手机号"
          v-model="loginphonenum"
          class="input1"
        />
        <input
          type="text"
          placeholder="请设置密码"
          v-model="loginpassword"
          class="input2"
        />
        <div class="logins" @click="login">登录</div>
        <div class="return">
          <span>其他登录方式</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { LoginApi ,ZhuceApi} from "../request/api";
export default {
  data() {
    return {
      isshow: 1,
      kuangshow: false,  
      loginphonenum: "18628850235",
      loginpassword: "52162418pxr",
      userinfo:''
    };
  },
  methods: {
    closeLogin() {
      return this.$store.commit("ChangeLoginShow", false);
    },
    goLogin() {
      if (this.kuangshow == false) {
        console.log(this.$store.state.ToastShow);
        return this.$store.dispatch("AsyncToast");
      } else {
        this.isshow = 4;
      }
    },
    gozhuce() {
      if (this.kuangshow == false) {
        console.log(this.$store.state.ToastShow);
        return this.$store.dispatch("AsyncToast");
      } else {
        this.isshow = 3;
      }
    },
 
    login() {
    
        LoginApi({phone:this.loginphonenum,password:this.loginpassword}).then((res)=>{
          console.log(res);
          if(res.data.code===200){
            this.userinfo=res.data.profile
          localStorage.setItem('token',res.data.token)
          localStorage.setItem('id',res.data.profile.userId)
          this.$emit("updateKeyFn");
          this.$store.commit('ChangeLoginShow',false)
          this.$router.push('/')
          }else{
            alert('账号错误')
          }
        })
      
    },
  },
  
};
</script>
 
<style lang = "less" scoped>
@import "../assets/base";
.modal {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  .modal_in {
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
  }
  .content {
    position: absolute;

    left: 0;
    top: 0;
    bottom: 0;
    right: 0;
    margin: auto;
    width: 530px;
    height: 360px;
    background-color: #fff;
    .content_top {
      width: 100%;
      height: 50px;
      background-color: rgb(45, 45, 45);
      color: #fff;
      line-height: 50px;
      position: relative;
    }
    .topl {
      position: absolute;
      left: 20px;
    }
    .topr {
      position: absolute;
      right: 20px;
      cursor: pointer;
    }
    img {
      position: absolute;
      left: 0;
      right: 0;
      top: 0;
      bottom: 0;
      margin: auto;
    }
    button {
      padding: 5px 10px;
      position: absolute;
      bottom: 20px;
      left: 50%;
      transform: translateX(-50%);
      border-radius: 10px;
      cursor: pointer;
    }
  }
}
.phone {
  width: 100%;
  height: 100%;
  .phonel {
    width: 320px;
    height: 310px;
    border-right: 1px solid #ccc;
    position: relative;
    .img {
      width: 100%;
      height: 120px;
      position: absolute;
      top: 20px;
    }
    .button {
      position: absolute;
      left: 50%;
      transform: translateX(-50%);
      width: 200px;
      height: 30px;
      border: 1px solid #ccc;
      box-sizing: border-box;
      text-align: center;
      line-height: 30px;
    }
    .phoneLogin {
      bottom: 100px;
      color: #fff;
      background-color: rgb(83, 189, 231);
    }
    .zhuce {
      bottom: 60px;
    }
    .agree {
      width: 100%;
      position: absolute;
      bottom: 20px;
      font-size: 12px;
      .kuang {
        width: 12px;
        height: 12px;
        border: 1px solid #ccc;
        margin-left: 30px;
        color: #fff;
      }
      .blue {
        background-color: rgb(3, 145, 145);
      }
    }
  }
  .phoner {
    width: 210px;
    height: 310px;
    /* background-color: skyblue; */

    p {
      height: 30px;
      line-height: 30px;
      margin-top: 30px;
      font-size: 14px;
      vertical-align: middle;
      margin-left: 50px;
      i {
        font-size: 24px;
      }
    }
  }
}
.zhuce {
  width: 100%;
  height: 80%;
  position: relative;
  input {
    display: block;
    position: absolute;
    width: 200px;
    height: 30px;
    left: 50%;
    transform: translateX(-50%);
    top: 10%;
    outline: none;
  }
  .input2 {
    top: 25%;
  }
  .next {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 200px;
    height: 30px;
    border: 1px solid #ccc;
    text-align: center;
    top: 40%;
    line-height: 30px;
    background-color: rgb(26, 138, 182);
    color: #fff;
    cursor: pointer;
  }
  .return {
    width: 100%;
    position: absolute;
    bottom: 20px;
    border-top: 1px solid #ccc;
    padding: 10px;
    box-sizing: border-box;

    span {
      display: inline-block;
      height: 30px;
      cursor: pointer;
    }
    span:hover {
      color: rgb(89, 156, 182);
    }
  }
}
.login {
  width: 100%;
  height: 80%;
  position: relative;
  input {
    display: block;
    position: absolute;
    width: 200px;
    height: 30px;
    left: 50%;
    transform: translateX(-50%);
    top: 10%;
    outline: none;
  }
  .input2 {
    top: 25%;
  }
  .logins {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 200px;
    height: 30px;
    border: 1px solid #ccc;
    text-align: center;
    top: 40%;
    line-height: 30px;
    background-color: rgb(26, 138, 182);
    color: #fff;
    cursor: pointer;
  }
  .return {
    width: 100%;
    position: absolute;
    bottom: 20px;
    border-top: 1px solid #ccc;
    padding: 10px;
    box-sizing: border-box;

    span {
      display: inline-block;
      height: 30px;
      cursor: pointer;
    }
    span:hover {
      color: rgb(89, 156, 182);
    }
  }
}
</style>